package com.example.controller;

import com.example.service.IUserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class UserController {

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    IUserService userService;

    @GetMapping("/hello")
    @HystrixCommand(fallbackMethod = "helloFail")
    public String test(){
        return restTemplate.getForObject("http://eureka-provider-user/hello",String.class);
    }

    @GetMapping("/helloFeign")
    public String testFeign(){
        return userService.test();
    }

    public String helloFail(){
        return "hello fail";
    }
}
